package com.imooc.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.imooc.dataobject.OrderDetail;
import com.imooc.enums.OrderStatusEnum;
import com.imooc.enums.PayStatusEnum;
import com.imooc.utils.EnumUtils;
import com.imooc.utils.serializer.Date2LongSerializer;
import lombok.Data;

import javax.persistence.Id;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 功能描述: <br>
 * (订单传输对象)
 *
 * @Author:Mr. xyb
 * @Date: 2018/5/18 14:45
 * @since: 1.8.0
 * @version: 1.0.0
 */
@Data
// @JsonInclude(JsonInclude.Include.NON_NULL)// 在返回的对象中不显示为null的属性
public class OrderDto {
    /*订单id*/
    @Id
    private String orderId;

    /*买家名字*/
    private String buyerName;

    /*买家手机号*/
    private String buyerPhone;

    /*买家地址*/
    private String buyerAddress;

    /*买家openid*/
    private String buyerOpenid;

    /*订单总金额*/
    private BigDecimal orderAmount;

    /*订单状态,默认为0新下单 */
    private Integer orderStatus;

    /*支付状态,默认为0等待支付*/
    private Integer payStatus;

    /*创建时间*/
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date createTime;

    /*更新时间*/
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date updateTime;

    /*订单详情*/
    List<OrderDetail> orderDetailList;

    /*订单状态名称，当对象转为json时忽略此属性*/
    @JsonIgnore
    public OrderStatusEnum getOrderStatusEnum() {
        return EnumUtils.getCode(orderStatus, OrderStatusEnum.class);
    }

    /*支付状态名称，当对象转为json时忽略此属性*/
    @JsonIgnore
    public PayStatusEnum getPayStatusEnum() {
        return EnumUtils.getCode(payStatus, PayStatusEnum.class);
    }

}
